<template>
  <el-dialog
    v-el-drag-dialog
    :title="!dataForm.id ? '物流记录' : '物流记录'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm.list" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-table :data="dataForm.list">
        <el-table-column label="时间">
          <template slot-scope="scope">
            <span>{{scope.row.time}}</span>
          </template>
        </el-table-column>
        <el-table-column label="物流记录">
          <template slot-scope="scope">
            <span>{{scope.row.content}}</span>
          </template>
        </el-table-column>
      </el-table>
    <el-form-item label="信息记录" prop="list">
      <template slot-scope="scope">
        <span>{{scope.row.time}}</span>
      </template>
    </el-form-item>
    <el-form-item label="物流单号" prop="expressName">
        <el-input v-model="dataForm.expressNo" placeholder="物流公司" disabled="true"></el-input>
    </el-form-item>
    <el-form-item label="物流公司" prop="expressName">
      <el-input v-model="dataForm.expressName" placeholder="物流公司" disabled="true"></el-input>
    </el-form-item>
    <el-form-item label="物流电话" prop="expressPhone">
        <el-input v-model="dataForm.expressPhone" placeholder="物流电话" disabled="true"></el-input>
    </el-form-item>
    <el-form-item label="网址" prop="site">
      <el-input v-model="dataForm.site" placeholder="网址" disabled="true"></el-input>
    </el-form-item>
    </el-form>
    <!-- <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span> -->
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          orderId: '',
          shipCode: '',
          list: [],
          companyId: '',
          expressNo: '',
          expressName: '',
          expressPhone: '',
          site: ''
        },
        dataRule: {
          addtime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (shipCode) {
        // this.dataForm.orderId = orderId
        // this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
        //   if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl(`/shopping/order/getLogisticsInformationByExpressNo/${shipCode}`),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.dataForm.list = data.data.list
              this.dataForm.expressNo = data.data.expressNo
              this.dataForm.expressPhone = data.data.expressPhone
              this.dataForm.expressName = data.data.expressName
              this.dataForm.site = data.data.site
                // this.dataForm.companyName = data.data.companyName
                // this.dataForm.companyId = data.data.companyId
            }
          })
        //   }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/shopping/order/modifyOrderShipmentById`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'companyId': this.dataForm.companyId,
                'shipCode': this.dataForm.shipCode
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
